<template xmlns:v-lazy="http://www.w3.org/1999/xhtml">
  <div class="tool-photo">
    <w-nav-bar
      title="OOS/图片"/>
    <ul class="table-view w-flex-between">
      <li
        v-for="(v, k) in loadListModel.dataArr"
        :key="v.name"
        class="image-box w-image-fit"
        @click.self="imageClick(k)"
        v-lazy:background-image="v.cdnUrl || defaultImage">
        <icon-remove
          class="remove-icon w-round"
          @click.native="removeClick(v, k)"/>
      </li>
    </ul>
    <w-viewer ref="IMAGE_SHOW"/>
    <w-load-more :load-model="loadListModel"/>
  </div>
</template>

<script>
  import OSSListLoad from '@/models/oss/OSSListLoad'
  import Config from '@/config/index'
  import IconRemove from '@/icons/remove.svg'
  import WViewer from '@/components/global/viewer/index'
  import WLoadMore from '@/components/global/loadMore/index'
  export default {
    name: 'SetAdminOss',
    components: {
      IconRemove,
      WViewer,
      WLoadMore
    },
    data() {
      return {
        /**
         * 默认图片
         */
        defaultImage: Config.defaultImage,
        /**
         * 列表加载模型
         */
        loadListModel: new OSSListLoad('ybweb', 'images/OSS'),
      }
    },
    methods: {
      /**
       * 加载列表数据
       */
      loadListData () {
        this.loadListModel.loadData().w_then()
      },
      /**
       * 图片点击
       * @param k
       */
      imageClick(k) {
        const arr = this.loadListModel.dataArr.map((v) => {
          return v.url
        })
        this.$refs['IMAGE_SHOW'].show(arr, k)
      },
      /**
       * 删除按钮点击
       * @param v
       * @param k
       * @returns {Promise<void>}
       */
      async removeClick(v, k) {
        this.$w_remove_pop(() => {
          return v.removeData(Config.photoBocket)
        }, '图片').w_then(() => {
          this.loadListModel.removeWithIndex(k)
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
  .tool-photo {
    >.table-view {
      list-style: none;
      margin: 0;
      padding: 10px;
      flex-wrap: wrap;
      >.image-box {
        width: 185px;
        height: 185px;
        margin-bottom: 5px;
        position: relative;
        z-index: 0;
        >.remove-icon {
          position: absolute;
          right: 0px;
          top: 0px;
          width: 40px;
          height: 40px;
          background-color: rgba(3,3,3,.5);
          fill: #fff;
        }
      }
    }
  }
</style>
